//
//  WMTabBarController.m
//  Mink
//
//  Created by 周述坚 on 17/6/22.
//  Copyright © 2017年 周述坚. All rights reserved.
//

#import "WMTabBarController.h"
#import "WMNavigationViewController.h"

@interface WMTabBarController ()

@end

@implementation WMTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addController];
}


- (void)addController{
    //1.创建控制器
    UIViewController *home = [self getControllerWithClassName:@"WMHomeViewController" andTitle:@"首页" andImgName:@"ic_album"];
    UIViewController *photo = [self getControllerWithClassName:@"WMPhotoViewController" andTitle:@"相册" andImgName:@"ic_home"];
    UIViewController *setting = [self getControllerWithClassName:@"WMSettingViewController" andTitle:@"设置" andImgName:@"ic_discover"];
    self.viewControllers = @[home,photo,setting];
    self.tabBar.barTintColor = [UIColor whiteColor];
}

/**
 *  根据传入的参数创建控制器
 *
 *  @param cName   控制器类名
 *  @param title   导航和tabBar的标题
 *  @param imgName tabBar的图片
 *
 *  @return 控制器
 */
- (UIViewController *)getControllerWithClassName:(NSString *)cName andTitle:(NSString *)title andImgName:(NSString *)imgName{
    
    //1.创建导航控制器的根controler
    Class class = NSClassFromString(cName);
    UIViewController *controller = [[class alloc]init];
    
    //2.为controller设置title和tabBar的图片
    //--设置title
    controller.title = title;
    //--设置tabBar的图片
    UIImage *normalimg = [UIImage imageNamed:imgName];
    UIImage *selectimg = [UIImage imageNamed:[imgName stringByAppendingString:@"_selected"]];
    controller.tabBarItem.image = [normalimg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    controller.tabBarItem.selectedImage = [selectimg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //3.创建导航控制器
    WMNavigationViewController *naController = [[WMNavigationViewController alloc]initWithRootViewController:controller];
    
    //4.返回导航控制器
    return naController;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
